﻿namespace OS {
	class File {
		
		field _0; // file connection, if any
		field _t; // is file open
		// TODO: open for read or write?

		constructor() {
			// assign _0 externally
		}

		static method openRead(path, isBinary=false) {
			argmatch(STRING, BOOL) {
				f = new File();
				f._0 = @os_file_openread;
				f._t = true;
				return f;
			} else {
				throw new InvalidArgumentException();
			}
		}

		static method openWrite(path, isBinary=false) {

		}

		// returns the next character
		method readChar() {

		}

		// returns the next byte as an integer
		method readByte() {

		}

		method close() {
			if (this._t) {
				@os_file_close(this._0);
				this._t = false;
			} else {
				throw new FileAlreadyClosedExceptionOrSomething();
			}
		}

		// returns all file contents as a string
		method readAllText() {
			if (this._t) {
				return @os_file_readalltext(this._0);
			} else {
				throw new FileAlreadyClosedExceptionOrSomething();
			}
		}

		method readLine() {
			
		}
	}
}
